var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        curPage : "/zofui_sales/live/mylive",
        page : {
            isend : false,
            doing : false,
            doo : 'live',
            pdata : {
                op : 'mylive',
                page : 1,
                type : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        tabs : [],
		actgoods : {},
    },
    onLoad:function(options){
        var self = this;
        
		var shopid = options.shopid ? options.shopid : 0;
        var zfid = options.zfid ? options.zfid : '';
        self.setData({
            options : options,
            'page.pdata.status' : options.status ? options.status : 0,
            'page.pdata.zfid' : zfid,
        });

        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   sharedata : res.data.data.sharedata,
                   params : res.data.data.params,
                   actgoods : res.data.data.actgoods ? res.data.data.actgoods : {},
                },function(){
                    self.setData({
                        inited : true,
                    });
                });
                
                wx.setNavigationBarTitle({
                    title:  '我的直播',
                });

            },false,function(res){
                app.com.alert(res.data.message);
            });
			app.com.setBar(app,self);
        });

    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            datalist : [],
            isdown : true,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0,
            'page.pdata.isinit' : 1,
        });
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    onChange(e){
        var self = this;
        if( self.data.ising || ( e.detail.index == self.data.page.pdata.type ) ) return false;
        self.data.ising = true;

        self.setData({
            datalist : [],
            'page.pdata.type' : e.detail.index,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
        self.data.ising = false;
    },
    delsub(e){
        var i = e.currentTarget.dataset.i;
        var self = this;
        var postdata = {
            op : 'sublive',
            id :  self.data.datalist[i].id,
        };
        
        app.com.http('live','POST',postdata,0,true,'','',function(res){
            if ( !res.data.errno && res.data.errno !== undefined ) {
                self.data.datalist.splice(i,1);
                self.setData({
                    datalist : self.data.datalist
                })
                
                app.com.toast(res.data.message);
            }else{
                app.com.alert(res.data.message);
            }
        });

    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    }
    

})